function GameMenu()
{
  RenderMap();
  
  WindowStyle.drawWindow(8, 8, 40, 12);
  Font.drawText(10, 10, "Menu");

  // execute the menu
  var menu = new Menu();
  menu.font         = Font;
  menu.window_style = WindowStyle;
  menu.arrow        = Arrow;
  menu.addItem("Items",  Menu_Items);
  menu.addItem("Equip",  Menu_Equip);
  menu.addItem("Inventory",  Menu_Inventory);
  menu.addItem("Magic",  Menu_WhiteMagic);
  menu.addItem("Special",  Menu_Special);
  menu.addItem("Status", Menu_Status);
  menu.addItem("Save",   Menu_Save);
  menu.addItem("Quit",   Menu_Quit);
  menu.execute(6, 34, 130, 65);
}

function Menu_Items()
{
  RenderMap();
  
  WindowStyle.drawWindow(8, 8, 624, 12);
  Font.drawText(10, 10, "Item Menu");

  // execute the menu
  var ItemMenu = new Menu();
  ItemMenu.font         = Font;
  ItemMenu.window_style = WindowStyle;
  ItemMenu.arrow        = Arrow;

  if (Player.items.potion >= 1)
  {
  ItemMenu.addItem("Potion" + ":" + Player.items.potion,  ItemMenuPotion);
  }
  if (Player.items.hipotion >= 1)
  {
  ItemMenu.addItem("Hi-Potion" + ":" + Player.items.hipotion,  ItemMenuHiPotion);
  }
  if (Player.items.fullpotion >= 1)
  {
  ItemMenu.addItem("Full-Potion" + ":" + Player.items.fullpotion,  ItemMenuFullPotion);
  }
  if (Player.items.ether >= 1)
  {
  ItemMenu.addItem("Ether" + ":" + Player.items.ether,  ItemMenuEther);
  }
  if (Player.items.turboether >= 1)
  {
  ItemMenu.addItem("Turbo-Ether" + ":" + Player.items.turboether,  ItemMenuTurboEther);
  }
  if (Player.items.elixer >= 1)
  {
  ItemMenu.addItem("Elixer" + ":" + Player.items.elixer,  ItemMenuElixer);
  }
  if (Player.items.life >= 1)
  {
  ItemMenu.addItem("Life" + ":" + Player.items.life,  ItemMenuLife);
  }
  if (Player.items.tent >= 1)
  {
  ItemMenu.addItem("Tent" + ":" + Player.items.tent,  ItemMenuTent);
  }
  ItemMenu.addItem("Cancel", GameMenu);
  ItemMenu.execute(6, 34, 272, 140);


}
//------------------Item useage code-----------------

function ItemMenuPotion()
{
Player.temp = "potion";
Use_Item_Menu();

}
function ItemMenuHiPotion()
{
Player.temp = "hipotion";
Use_Item_Menu();

}
function ItemMenuFullPotion()
{
Player.temp = "fullpotion";
Use_Item_Menu();

}
function ItemMenuEther()
{
Player.temp = "ether";
Use_Item_Menu();

}
function ItemMenuTurboEther()
{
Player.temp = "turboether";
Use_Item_Menu();

}
function ItemMenuElixer()
{
Player.temp = "elixer";
Use_Item_Menu();

}
function ItemMenuLife()
{
Player.temp = "life";
Use_Item_Menu();
}

function ItemMenuTent()
{
  if (Player.tentsave == true)
  {
    Player.day = Player.day + 1;
    RenderMap()
    FadeToColor(500, Black);
    
    if (Player.hp > 0)
    {
    Player.hp = Player.maxhp;
    Player.mp = Player.maxmp;
    }
    if (Player2.pres == true)
    {
      if (Player2.hp > 0)
      {
      Player2.hp = Player2.maxhp;
      Player2.mp = Player2.maxmp;
      }        
    }
    if (Player3.pres == true)
    {
      if (Player3.hp > 0)
      {
      Player3.hp = Player3.maxhp;
      Player3.mp = Player3.maxmp;
      }        
    }
    Delay(500);
    FadeFromColor(500, Black);
    Talk_Window("Hp and Mp Restored!", Player.port); 
    Player.items.tent = Player.items.tent - 1;  
  }
  else
  {
    Talk_Window("You can't use that here!", "blank.png");
    Menu_Items();
  }

}

function Use_Item_Menu()
{

  RenderMap();
  WMagicStats();

  WindowStyle.drawWindow(8, 8, 140, 12);
  Font.drawText(10, 10, "Which Character?");
  
  // execute the menu
  var UseItemMenu = new Menu();
  UseItemMenu.font         = Font;
  UseItemMenu.window_style = WindowStyle;
  UseItemMenu.arrow        = Arrow;
  UseItemMenu.addItem(Player.name,  UseItemPlayer);


  if (Player2.pres == true)
  {
  UseItemMenu.addItem(Player2.name,  UseItemPlayer2);
  }
  if (Player3.pres == true)
  {
  UseItemMenu.addItem(Player3.name,  UseItemPlayer3);
  }
  
  UseItemMenu.addItem("Cancel",  Menu_Items);
    
  UseItemMenu.execute(6, 34, 142, 40);
}

function UseItemPlayer()
{

  if (Player.temp == "potion")
  {
    if (Player.hp == 0)
    {
    Talk_Window("You can't use that on a wounded person!", "blank.png");
    }
    else
    {
      Player.hp = Player.hp + 50
  
      if (Player.hp >= Player.maxhp)
      {
        Player.hp = Player.maxhp
      }
      Player.items.potion = Player.items.potion - 1
      
    }
  }

  else if (Player.temp == "hipotion")
  {
    if (Player.hp == 0)
    {
    Talk_Window("You can't use that on a wounded person!", "blank.png");
    }
    else
    {
      Player.hp = Player.hp + 250
  
      if (Player.hp >= Player.maxhp)
      {
        Player.hp = Player.maxhp
      }
      Player.items.hipotion = Player.items.hipotion - 1
      
    }
  }
  else if (Player.temp == "fullpotion")
  {
    if (Player.hp == 0)
    {
    Talk_Window("You can't use that on a wounded person!", "blank.png");
    }
    else
    {
      Player.hp = Player.maxhp
      Player.items.fullpotion = Player.items.fullpotion - 1
      
    }
  }
  else if (Player.temp == "ether")
  {
    if (Player.hp == 0)
    {
    Talk_Window("You can't use that on a wounded person!", "blank.png");
    }
    else
    {
      Player.mp = Player.mp + 50
  
      if (Player.mp >= Player.maxmp)
      {
        Player.mp = Player.maxmp
      }
      Player.items.ether = Player.items.ether - 1
      
    }
  }
  else if (Player.temp == "turboether")
  {
    if (Player.hp == 0)
    {
    Talk_Window("You can't use that on a wounded person!", "blank.png");
    }
    else
    {
      Player.mp = Player.maxmp
      Player.items.turboether = Player.items.turboether - 1
      
    }
  }

  else if (Player.temp == "elixer")
  {
    if (Player.hp == 0)
    {
    Talk_Window("You can't use that on a wounded person!", "blank.png");
    }
    else
    {
      Player.mp = Player.maxmp
      Player.hp = Player.maxhp
      Player.items.elixer = Player.items.elixer - 1
      
    }
  }
  else if (Player.temp == "life")
  {
    if (Player.hp == 0)
    {
      Player.hp = Math.floor(Player.maxhp/5)
      Player.items.life = Player.items.life - 1
      
    }
    else
    {
    Talk_Window("I don't need that!", Player.port);
    }    
  }

Menu_Items();
}
//------For the other Player on your party...
function UseItemPlayer2()
{

  if (Player.temp == "potion")
  {
    if (Player2.hp == 0)
    {
    Talk_Window("You can't use that on a dead person!", "blank.png");
    }
    else
    {
      Player2.hp = Player2.hp + 50
  
      if (Player2.hp >= Player2.maxhp)
      {
        Player2.hp = Player2.maxhp
      }
      Player.items.potion = Player.items.potion - 1
      
    }
  }
  else if (Player.temp == "hipotion")
  {
    if (Player2.hp == 0)
    {
      Talk_Window("You can't use that on a dead person!", "blank.png");
    }
    else
    {
      Player2.hp = Player2.hp + 250
  
      if (Player2.hp >= Player2.maxhp)
      {
        Player2.hp = Player2.maxhp
      }
      Player.items.hipotion = Player.items.hipotion - 1
      
    }
  }
  else if (Player.temp == "fullpotion")
  {
    if (Player2.hp == 0)
    {
      Talk_Window("You can't use that on a dead person!", "blank.png");
    }
    else
    {

      Player2.hp = Player2.maxhp
      Player.items.fullpotion = Player.items.fullpotion - 1
      
    }
  }
  else if (Player.temp == "ether")
  {
    if (Player2.hp == 0)
    {
      Talk_Window("You can't use that on a dead person!", "blank.png");
    }
    else
    {
      Player2.mp = Player2.mp + 50
    
      if (Player2.mp >= Player2.maxmp)
      {
        Player2.mp = Player2.maxmp
      }
      Player.items.ether = Player.items.ether - 1
      
    }
  }
  else if (Player.temp == "turboether")
  {
    if (Player2.hp == 0)
    {
      Talk_Window("You can't use that on a dead person!", "blank.png");
    }
    else
    {
      Player2.mp = Player2.maxmp
      Player.items.turboether = Player.items.turboether - 1
      
    }
  }

  else if (Player.temp == "elixer")
  {
    if (Player2.hp == 0)
    {
      Talk_Window("You can't use that on a dead person!", "blank.png");
    }
    else
    {
      Player2.mp = Player2.maxmp
      Player2.hp = Player2.maxhp
      Player.items.elixer = Player.items.elixer - 1
      
    }
  }
  else if (Player.temp == "life")
  {
    if (Player2.hp == 0)
    {
      Player2.hp = Math.floor(Player2.maxhp/5)
      Player.items.life = Player.items.life - 1
      
    }
    else
    {
    Talk_Window("I'm still alive!", Player2.port);
    }    
  }

Menu_Items();
}
function UseItemPlayer3()
{

  if (Player.temp == "potion")
  {
    if (Player3.hp == 0)
    {
      Talk_Window("You can't use that on a dead person!", "blank.png");
    }
    else
    {
      Player3.hp = Player3.hp + 50
  
      if (Player3.hp >= Player3.maxhp)
      {
        Player3.hp = Player3.maxhp
      }
      Player.items.potion = Player.items.potion - 1
      
    }
  }
  else if (Player.temp == "hipotion")
  {
    if (Player3.hp == 0)
    {
      Talk_Window("You can't use that on a dead person!", "blank.png");
    }
    else
    {
      Player3.hp = Player3.hp + 250
  
      if (Player3.hp >= Player3.maxhp)
      {
        Player3.hp = Player3.maxhp
      }
      Player.items.hipotion = Player.items.hipotion - 1
      
    }
  }
  else if (Player.temp == "fullpotion")
  {
    if (Player3.hp == 0)
    {
      Talk_Window("You can't use that on a dead person!", "blank.png");
    }
    else
    {

      Player3.hp = Player3.maxhp
      Player.items.fullpotion = Player.items.fullpotion - 1
      
    }
  }
  else if (Player.temp == "ether")
  {
    if (Player3.hp == 0)
    {
      Talk_Window("You can't use that on a dead person!", "blank.png");
    }
    else
    {
      Player3.mp = Player3.mp + 50
  
      if (Player.mp >= Player.maxmp)
      {
        Player3.mp = Player3.maxmp
      }
      Player.items.ether = Player.items.ether - 1
      
    }
  }
  else if (Player.temp == "turboether")
  {
    if (Player3.hp == 0)
    {
      Talk_Window("You can't use that on a dead person!", "blank.png");
    }
    else
    {
      Player3.mp = Player3.maxmp
      Player.items.turboether = Player.items.turboether - 1
      
    }
  }

  else if (Player.temp == "elixer")
  {
    if (Player3.hp == 0)
    {
      Talk_Window("You can't use that on a dead person!", "blank.png");
    }
    else
    {
      Player3.mp = Player3.maxmp
      Player3.hp = Player3.maxhp
      Player.items.elixer = Player.items.elixer - 1
      
    }
  }
  else if (Player.temp == "life")
  {
    if (Player3.hp == 0)
    {
      Player3.hp = Math.floor(Player3.maxhp/5)
      Player.items.life = Player.items.life - 1
      
    }
    else
    {
    Talk_Window("I'm still alive!", Player3.port);
    }    
  }

Menu_Items();
}

//Finally, on to the rest of the game menu.....
function Menu_Equip()
{
  RenderMap();
  
  WindowStyle.drawWindow(8, 8, 200, 12);
  Font.drawText(10, 10, "Equip Which Character?");

  // execute the menu
  var equmenu = new Menu();
  equmenu.font         = Font;
  equmenu.window_style = WindowStyle;
  equmenu.arrow        = Arrow;
  equmenu.addItem(Player.name,  Player1equ);
  if (Player2.pres == true)
  {
  equmenu.addItem(Player2.name,  Player2equ);
  }
  if (Player3.pres == true)
  {
  equmenu.addItem(Player3.name,  Player3equ);
  }
  equmenu.addItem("Cancel", equipmenuquit);  

  equmenu.execute(6, 34, 202, 60);

// Font.drawTextBox (75, 30, 500, 100, 5, "Dagger: " + Playerweapons.Dagger);
// Font.drawTextBox (75, 40, 500, 100, 5, "Short Sword: " + Playerweapons.Short_Sword);
// Font.drawTextBox (75, 50, 500, 100, 5, "Long Sword: " + Playerweapons.Long_Sword);

}
function equipmenuquit()
{
GameMenu();
}
function Player1equ()
{
  if (Player.port == "Dagnar.png")
  {
  Talk_Window("Don't touch my stuff.", Player.port)
  Menu_Equip();
  }
  else
  {
  Player.equipperson = "Player1";
  Playerequipmenu();
  }
}
function Player2equ()
{
  if (Player2.port == "Dagnar.png")
  {
  Talk_Window("Don't touch my stuff.", Player2.port)
  Menu_Equip();
  }
  else
  {
  Player.equipperson = "Player2";
  Playerequipmenu();
  }
}
function Player3equ()
{
  if (Player3.port == "Dagnar.png")
  {
  Talk_Window("Don't touch my stuff.", Player3.port)
  Menu_Equip();
  }
  else
  {
  Player.equipperson = "Player3";
  Playerequipmenu();
  }
}

//-------------------The Stats Menu-----------------
function Menu_Status()
{
 Player.tonextlevel = Player.nextlevel - Player.exp;
 Player2.tonextlevel = Player2.nextlevel - Player2.exp;
 Player3.tonextlevel = Player3.nextlevel - Player3.exp;


 RenderMap() 
 WindowStyle.drawWindow (25, 25, 590, 430);
 Portrait = LoadImage(Player.port);
 Portrait.blit(30, 30);
 if (Player.hp <= 0)
 {
 Font.drawTextBox (75, 30, 500, 100, 5, Player.name + "(Wounded)");
 }
 else
 {
 Font.drawTextBox (75, 30, 500, 100, 5, Player.name);
 }
 Font.drawTextBox (75, 40, 500, 100, 5, "Class: " + Player.chrclass);
 Font.drawTextBox (200, 40, 500, 100, 5, "Level: " + Player.level);
 Font.drawTextBox (200, 50, 500, 100, 5, "Exp: " + Player.exp);
 Font.drawTextBox (200, 60, 500, 100, 5, "To Next Level: " + Player.tonextlevel);
 

 Font.drawTextBox (75, 50, 500, 100, 5, "HP:" + Player.hp + "/" + Player.maxhp);
 Font.drawTextBox (75, 60, 500, 100, 5, "MP:" + Player.mp + "/" + Player.maxmp);
 Font.drawTextBox (75, 70, 500, 100, 5, "Str: " + Player.str);
 if (Player.chrclass == "Mage")
 {
   if (Player.level > 3)
   {
     if (Player.customnumber < 11)
     {
     Player.numbertemp = Player.customlearn + 1;
     Font.drawTextBox (200, 70, 500, 100, 5, "Levels to create new magic: " + Player.numbertemp);
     }
     else
     {
     }
   }
 }

 Font.drawTextBox (75, 80, 500, 100, 5, "Agi: " + Player.agi);
 Font.drawTextBox (75, 90, 500, 100, 5, "Mag: " + Player.mag);
 Font.drawTextBox (75, 100, 500, 100, 5, "Vit: " + Player.vit);
 Font.drawTextBox (75, 110, 500, 100, 5, "Luck: " + Player.luck); 

 Font.drawTextBox (200, 80, 500, 100, 5, "Atk: " + Player.attack);
 Font.drawTextBox (200, 90, 500, 100, 5, "Def: " + Player.defence);
 Font.drawTextBox (200, 100, 500, 100, 5, "MAtk: " + Player.mattack);
 Font.drawTextBox (200, 110, 500, 100, 5, "Evade: " + Player.evade + "%"); 
 

 Font.drawTextBox (75, 130, 500, 100, 5, "Weapon: " + Player.equipwep); 
 Font.drawTextBox (300, 130, 500, 100, 5, "Armour: " + Player.equiparmour);
 
if (Player2.pres == true)
{
 Portrait = LoadImage(Player2.port);
 Portrait.blit(30, 150);
 if (Player2.hp <= 0)
 {
 Font.drawTextBox (75, 150, 500, 100, 5, Player2.name + "(Wounded)");
 }
 else
 {
 Font.drawTextBox (75, 150, 500, 100, 5, Player2.name);
 }
 Font.drawTextBox (75, 160, 500, 100, 5, "Class: " + Player2.chrclass);
 Font.drawTextBox (200, 160, 500, 100, 5, "Level: " + Player2.level);
 Font.drawTextBox (200, 170, 500, 100, 5, "Exp: " + Player2.exp);
 Font.drawTextBox (200, 180, 500, 100, 5, "To Next Level: " + Player2.tonextlevel);

 Font.drawTextBox (75, 170, 500, 100, 5, "HP:" + Player2.hp + "/" + Player2.maxhp);
 Font.drawTextBox (75, 180, 500, 100, 5, "MP:" + Player2.mp + "/" + Player2.maxmp);
 Font.drawTextBox (75, 190, 500, 100, 5, "Str: " + Player2.str);
 Font.drawTextBox (75, 200, 500, 100, 5, "Agi: " + Player2.agi);
 Font.drawTextBox (75, 210, 500, 100, 5, "Mag: " + Player2.mag);
 Font.drawTextBox (75, 220, 500, 100, 5, "Vit: " + Player2.vit);
 Font.drawTextBox (75, 230, 500, 100, 5, "Luck: " + Player2.luck); 
 
 Font.drawTextBox (200, 200, 500, 100, 5, "Atk: " + Player2.attack);
 Font.drawTextBox (200, 210, 500, 100, 5, "Def: " + Player2.defence);
 Font.drawTextBox (200, 220, 500, 100, 5, "MAtk: " + Player2.mattack);
 Font.drawTextBox (200, 230, 500, 100, 5, "Evade: " + Player2.evade + "%"); 

 Font.drawTextBox (75, 250, 500, 100, 5, "Weapon: " + Player2.equipwep); 
 Font.drawTextBox (300, 250, 500, 100, 5, "Armour: " + Player2.equiparmour);
}
if (Player3.pres == true)
{
 Portrait = LoadImage(Player3.port);
 Portrait.blit(30, 270);
 if (Player2.hp <= 0)
 {
 Font.drawTextBox (75, 270, 500, 100, 5, Player3.name + "(Wounded)");
 }
 else
 {
 Font.drawTextBox (75, 270, 500, 100, 5, Player3.name);
 }
 Font.drawTextBox (75, 280, 500, 100, 5, "Class: " + Player3.chrclass);
 Font.drawTextBox (200, 280, 500, 100, 5, "Level: " + Player3.level);
 Font.drawTextBox (200, 290, 500, 100, 5, "Exp: " + Player3.exp);
 Font.drawTextBox (200, 300, 500, 100, 5, "To Next Level: " + Player3.tonextlevel);

 Font.drawTextBox (75, 290, 500, 100, 5, "HP:" + Player3.hp + "/" + Player3.maxhp);
 Font.drawTextBox (75, 300, 500, 100, 5, "MP:" + Player3.mp + "/" + Player3.maxmp);
 Font.drawTextBox (75, 310, 500, 100, 5, "Str: " + Player3.str);
 Font.drawTextBox (75, 320, 500, 100, 5, "Agi: " + Player3.agi);
 Font.drawTextBox (75, 330, 500, 100, 5, "Mag: " + Player3.mag);
 Font.drawTextBox (75, 340, 500, 100, 5, "Vit: " + Player3.vit);
 Font.drawTextBox (75, 350, 500, 100, 5, "Luck: " + Player3.luck); 
  
 Font.drawTextBox (200, 320, 500, 100, 5, "Atk: " + Player3.attack);
 Font.drawTextBox (200, 330, 500, 100, 5, "Def: " + Player3.defence);
 Font.drawTextBox (200, 340, 500, 100, 5, "MAtk: " + Player3.mattack);
 Font.drawTextBox (200, 350, 500, 100, 5, "Evade: " + Player3.evade + "%"); 

 Font.drawTextBox (75, 370, 500, 100, 5, "Weapon: " + Player3.equipwep); 
 Font.drawTextBox (300, 370, 500, 100, 5, "Armour: " + Player3.equiparmour);
}
 Font.drawTextBox (30, 440, 500, 100, 5, "Quest: " + Player.quest);
 Font.drawTextBox (30, 430, 500, 100, 5, "GP:" + Player.gp);


 FlipScreen();
 eatKey()
 //while (IsKeyPressed(KEY_A)) { } // or key S!!

  // eat all keys that in the queue 
 // while (AreKeysLeft()) { 
 // GetKey(); }   
 while (IsKeyPressed(KEY_SPACE) == false) 
 {Delay(100);}
 {GetKey()}
GameMenu();
}

function Menu_Save()
{
TheSaveMenu();
}

function Menu_Quit()
{
  eatKey();
  RenderMap();
  
  WindowStyle.drawWindow(8, 8, 245, 12);
  Font.drawText(10, 10, "Are you sure you want to quit?");

  // execute the menu
  var menu = new Menu();
  menu.font         = Font;
  menu.window_style = WindowStyle;
  menu.arrow        = Arrow;
  menu.addItem("Yes",  Menu_Quit2);
  menu.addItem("No",  GameMenu);
  menu.execute(6, 34, 40, 18);
}
function Menu_Quit2()
{
  DestroyPerson("main character");
  BindKey(KEY_ESCAPE, "", "");
  ChangeMusic("");
  MainMenu();
}

//Show a Player's Hp and Mp...
function ShowPlayer1Stats()
{
Talk_Window("Hp: " + Player.hp + "/" + Player.maxhp + " Mp: " + Player.mp + "/" + Player.maxmp, Player.port);
} 
function ShowPlayer2Stats()
{
Talk_Window("Hp: " + Player2.hp + "/" + Player2.maxhp + " Mp: " + Player2.mp + "/" + Player2.maxmp, Player2.port);
} 
function ShowPlayer3Stats()
{
Talk_Window("Hp: " + Player3.hp + "/" + Player3.maxhp + " Mp: " + Player3.mp + "/" + Player3.maxmp, Player3.port);
} 
function ShowAllPlayersStats()
{
 RenderMap() 
 WindowStyle.drawWindow (25, 380, 590, 80);

 Font.drawTextBox (75, 400, 525, 60, 5, "Hp: " + Player.hp + "/" + Player.maxhp + " Mp: " + Player.mp + "/" + Player.maxmp);
  if (Player2.pres == true)
  {
   Font.drawTextBox (75, 420, 525, 60, 5, "Hp: " + Player2.hp + "/" + Player2.maxhp + " Mp: " + Player2.mp + "/" + Player2.maxmp);
  }
  if (Player3.pres == true)
  {
   Font.drawTextBox (75, 440, 525, 60, 5, "Hp: " + Player3.hp + "/" + Player3.maxhp + " Mp: " + Player3.mp + "/" + Player3.maxmp);
  }

FlipScreen();
eatKey();
while (IsKeyPressed(KEY_SPACE) == false) 
{Delay(100);}
{GetKey()}
}
